﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Plumbing;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YArchitech.Revit;

namespace YArchitech.Plumbing
{
	public partial class FormDrawVRefrigerantPipe : HYBaseForm
	{
		[DllImport("user32.dll")]
		public static extern bool SetForegroundWindow(IntPtr hWnd);

		[DllImport("user32.dll")]
		public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		private void FormDrawVRefrigerantPipe_FormClosed(object sender, FormClosedEventArgs e)
		{
			FormDrawVRefrigerantPipe.SetForegroundWindow(new YJKWindowHandle(Process.GetCurrentProcess().MainWindowHandle).Handle);
			this.SimulationPressESC();
		}

		public FormDrawVRefrigerantPipe()
		{
			this.InitializeComponent();
		}

		public FormDrawVRefrigerantPipe(Autodesk.Revit.DB.Document doc) : this()
		{
			this.doc = doc;
		}

		private void btnPipeSetting_Click(object sender, EventArgs e)
		{
			try
			{
				FormMultiLinePipeSetting formMultiLinePipeSetting = new FormMultiLinePipeSetting(this.doc);
				formMultiLinePipeSetting.tranStart = true;
				System.Drawing.Point location = base.Location;
				formMultiLinePipeSetting.Location = new System.Drawing.Point(location.X + 258, location.Y);
				if (formMultiLinePipeSetting.ShowDialog() == DialogResult.Cancel)
				{
					if (!base.ClientRectangle.Contains(Cursor.Position))
					{
						YJKWindowHandle hywindowHandle = new YJKWindowHandle(Process.GetCurrentProcess().MainWindowHandle);
						int wMsg = 7;
						FormDrawVRefrigerantPipe.SendMessage(hywindowHandle.Handle, wMsg, IntPtr.Zero, IntPtr.Zero);
					}
					else
					{
						base.Focus();
					}
				}
			}
			catch (Exception)
			{
				YJKMessageBox.Show("打开管道设置失败！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
			}
		}

		private void radioBtn_CheckedChanged(object sender, EventArgs e)
		{
			RadioButton radioButton = (RadioButton)sender;
			if (!radioButton.Checked)
			{
				return;
			}
			string name = radioButton.Name;
			uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(name);
			if (num <= 2035439693u)
			{
				if (num <= 640534546u)
				{
					if (num != 315173654u)
					{
						if (num != 640534546u)
						{
							return;
						}
						if (!(name == "rbGas"))
						{
							return;
						}
						this.Configs.IsGasPipe = true;
						return;
					}
					else
					{
						if (!(name == "rbIncreasing"))
						{
							return;
						}
						this.Configs.IsCustom = false;
						this.tbCustom.Enabled = false;
						return;
					}
				}
				else if (num != 1214267646u)
				{
					if (num != 2035439693u)
					{
						return;
					}
					if (!(name == "rbLiquid"))
					{
						return;
					}
					this.Configs.IsGasPipe = false;
					return;
				}
				else
				{
					if (!(name == "rbCustom"))
					{
						return;
					}
					this.Configs.IsCustom = true;
					this.tbCustom.Enabled = true;
					return;
				}
			}
			else if (num <= 2677227757u)
			{
				if (num != 2352869388u)
				{
					if (num != 2677227757u)
					{
						return;
					}
					if (!(name == "rbRelative"))
					{
						return;
					}
					this.Configs.IsRelative = true;
					this.lbStartOffset.Text = (this.lbEndOffset.Text = "偏移量(mm)");
					this.cbbStartRefer.Enabled = true;
					this.cbbEndRefer.Enabled = true;
					if (string.IsNullOrEmpty(this.Configs.StartReference))
					{
						this.cbbStartRefer.SelectedIndex = 0;
						this.Configs.StartReference = this.cbbStartRefer.Text.Trim();
					}
					else if (this.cbbStartRefer.Items.Contains(this.Configs.StartReference))
					{
						this.cbbStartRefer.SelectedIndex = this.cbbStartRefer.Items.IndexOf(this.Configs.StartReference);
						this.cbbStartRefer.Text = this.Configs.StartReference;
					}
					else
					{
						this.cbbStartRefer.SelectedIndex = 0;
					}
					if (string.IsNullOrEmpty(this.Configs.EndReference))
					{
						this.cbbEndRefer.SelectedIndex = 0;
						this.Configs.EndReference = this.cbbEndRefer.Text.Trim();
					}
					else if (this.cbbEndRefer.Items.Contains(this.Configs.EndReference))
					{
						this.cbbEndRefer.SelectedIndex = this.cbbEndRefer.Items.IndexOf(this.Configs.EndReference);
						this.cbbEndRefer.Text = this.Configs.EndReference;
					}
					else
					{
						this.cbbEndRefer.SelectedIndex = 0;
					}
					if (!string.IsNullOrEmpty(this.Configs.StartOffset))
					{
						if (this.cbbStartOffset.Items.Contains(this.Configs.StartOffset))
						{
							this.cbbStartOffset.SelectedIndex = this.cbbStartOffset.Items.IndexOf(this.Configs.StartOffset);
							this.cbbStartOffset.Text = this.Configs.StartOffset;
						}
						else
						{
							this.cbbStartOffset.Text = this.Configs.StartOffset;
						}
					}
					else
					{
						this.cbbStartOffset.SelectedIndex = this.cbbStartOffset.Items.IndexOf("0");
						this.Configs.StartOffset = "0";
					}
					if (string.IsNullOrEmpty(this.Configs.EndOffset))
					{
						this.cbbEndOffset.SelectedIndex = 0;
						this.Configs.EndOffset = this.cbbEndOffset.Text.Trim();
						return;
					}
					if (this.cbbEndOffset.Items.Contains(this.Configs.EndOffset))
					{
						this.cbbEndOffset.SelectedIndex = this.cbbEndOffset.Items.IndexOf(this.Configs.EndOffset);
						this.cbbEndOffset.Text = this.Configs.EndOffset;
						return;
					}
					this.cbbEndOffset.Text = this.Configs.EndOffset;
					return;
				}
				else
				{
					if (!(name == "rbAbsolute"))
					{
						return;
					}
					this.Configs.IsRelative = false;
					this.lbStartOffset.Text = "起点标高(mm)";
					this.lbEndOffset.Text = "终点标高(mm)";
					this.cbbStartRefer.Enabled = false;
					this.cbbEndRefer.Enabled = false;
					if (string.IsNullOrEmpty(this.Configs.StartReference))
					{
						this.cbbStartRefer.SelectedIndex = 0;
						this.Configs.StartReference = this.cbbStartRefer.Text.Trim();
					}
					else if (this.cbbStartRefer.Items.Contains(this.Configs.StartReference))
					{
						this.cbbStartRefer.SelectedIndex = this.cbbStartRefer.Items.IndexOf(this.Configs.StartReference);
						this.cbbStartRefer.Text = this.Configs.StartReference;
					}
					else
					{
						this.cbbStartRefer.SelectedIndex = 0;
					}
					if (string.IsNullOrEmpty(this.Configs.EndReference))
					{
						this.cbbEndRefer.SelectedIndex = 0;
						this.Configs.EndReference = this.cbbEndRefer.Text.Trim();
					}
					else if (this.cbbEndRefer.Items.Contains(this.Configs.EndReference))
					{
						this.cbbEndRefer.SelectedIndex = this.cbbEndRefer.Items.IndexOf(this.Configs.EndReference);
						this.cbbEndRefer.Text = this.Configs.EndReference;
					}
					else
					{
						this.cbbEndRefer.SelectedIndex = 0;
					}
					if (!string.IsNullOrEmpty(this.Configs.BottomLevel))
					{
						if (this.cbbStartOffset.Items.Contains(this.Configs.BottomLevel))
						{
							this.cbbStartOffset.SelectedIndex = this.cbbStartOffset.Items.IndexOf(this.Configs.BottomLevel);
							this.cbbStartOffset.Text = this.Configs.BottomLevel;
						}
						else
						{
							this.cbbStartOffset.Text = this.Configs.BottomLevel;
						}
					}
					else
					{
						this.Configs.BottomLevel = this.viewRange[0].ToString();
						this.cbbStartOffset.Text = this.viewRange[0].ToString();
					}
					if (string.IsNullOrEmpty(this.Configs.TopLevel))
					{
						this.Configs.TopLevel = this.viewRange[1].ToString();
						this.cbbEndOffset.Text = this.viewRange[1].ToString();
						return;
					}
					if (this.cbbEndOffset.Items.Contains(this.Configs.TopLevel))
					{
						this.cbbEndOffset.SelectedIndex = this.cbbEndOffset.Items.IndexOf(this.Configs.TopLevel);
						this.cbbEndOffset.Text = this.Configs.TopLevel;
						return;
					}
					this.cbbEndOffset.Text = this.Configs.TopLevel;
					return;
				}
			}
			else if (num != 2767177636u)
			{
				if (num != 3135217747u)
				{
					return;
				}
				if (!(name == "rbSplit"))
				{
					return;
				}
				this.rbLiquid.Visible = true;
				this.rbGas.Visible = true;
				this.Configs.IsIntegratedPipe = false;
				return;
			}
			else
			{
				if (!(name == "rbWhole"))
				{
					return;
				}
				this.rbLiquid.Visible = false;
				this.rbGas.Visible = false;
				this.Configs.IsIntegratedPipe = true;
				return;
			}
		}

		private void cbbLiquid_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.Configs.LiquidPipeDiameter = this.cbbLiquid.SelectedItem.ToString();
		}

		private void cbbAir_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.Configs.GasPipeDiameter = this.cbbAir.SelectedItem.ToString();
		}

		private void cbbReference_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (((System.Windows.Forms.ComboBox)sender).Name == "cbbStartRefer")
			{
				this.Configs.StartReference = this.cbbStartRefer.SelectedItem.ToString();
				return;
			}
			this.Configs.EndReference = this.cbbEndRefer.SelectedItem.ToString();
		}

		private void FormDrawVRefrigerantPipe_Load(object sender, EventArgs e)
		{
			this.Configs = this.GetUserData();
			this.InitData(this.Configs);
		}

		private void InitData(VPipeSetting configs)
		{
			IList<string> levels = this.GetLevels(this.doc);
			this.cbbStartRefer.Items.AddRange(levels.ToArray<string>());
			this.cbbEndRefer.Items.AddRange(levels.ToArray<string>());
			this.cbbStartOffset.Items.AddRange(this.CreateStartOffset(16).ToArray<string>());
			this.cbbEndOffset.Items.AddRange(this.CreateEndOffset(10).ToArray<string>());
			this.viewRange = this.GetViewRange(this.doc.ActiveView);
			if (configs.IsIntegratedPipe)
			{
				this.rbWhole.Checked = true;
			}
			else
			{
				this.rbSplit.Checked = true;
			}
			if (configs.IsGasPipe)
			{
				this.rbGas.Checked = true;
			}
			else
			{
				this.rbLiquid.Checked = true;
			}
			IList<string> pipeDiameters = this.GetPipeDiameters();
			this.cbbLiquid.Items.AddRange(pipeDiameters.ToArray<string>());
			this.cbbAir.Items.AddRange(pipeDiameters.ToArray<string>());
			this.cbbLiquid.SelectedItem = configs.LiquidPipeDiameter;
			this.cbbAir.SelectedItem = configs.GasPipeDiameter;
			if (configs.IsLocateAssist)
			{
				this.cbLocate.Checked = true;
			}
			this.tbAssistLength.Text = configs.AssistLength.ToString();
			this.tbAngle.Text = configs.AssistAngle.ToString();
			if (configs.IsCustom)
			{
				this.rbCustom.Checked = true;
			}
			else
			{
				this.rbIncreasing.Checked = true;
			}
			this.tbCustom.Text = configs.CustomNum;
			if (configs.IsAreaNum)
			{
				this.cbAreaNum.Checked = true;
				this.tbAreaNum.Enabled = true;
			}
			else
			{
				this.cbAreaNum.Checked = false;
				this.tbAreaNum.Enabled = false;
			}
			if (configs.IsBuildingNum)
			{
				this.cbBuildingNum.Checked = true;
				this.tbBuildingNum.Enabled = true;
			}
			else
			{
				this.cbBuildingNum.Checked = false;
				this.tbBuildingNum.Enabled = false;
			}
			this.tbAreaNum.Text = configs.AreaNum;
			this.tbBuildingNum.Text = configs.BuildingNum;
			if (configs.IsRelative)
			{
				this.rbRelative.Checked = true;
				return;
			}
			this.rbAbsolute.Checked = true;
		}

		private VPipeSetting GetUserData()
		{
			VPipeSetting vpipeSetting = new VPipeSetting();
			IDictionary<string, string> vrefrigerantPipeInfo = this.userSetting.GetVRefrigerantPipeInfo();
			if (string.IsNullOrEmpty(vrefrigerantPipeInfo["IsIntegratedPipe"]))
			{
				vpipeSetting.IsIntegratedPipe = true;
			}
			else
			{
				vpipeSetting.IsIntegratedPipe = !(vrefrigerantPipeInfo["IsIntegratedPipe"] == "0");
			}
			if (string.IsNullOrEmpty(vrefrigerantPipeInfo["IsGasPipe"]))
			{
				vpipeSetting.IsGasPipe = false;
			}
			else
			{
				vpipeSetting.IsGasPipe = !(vrefrigerantPipeInfo["IsGasPipe"] == "0");
			}
			if (string.IsNullOrEmpty(vrefrigerantPipeInfo["LiquidDiameter"]))
			{
				vpipeSetting.LiquidPipeDiameter = "12.7";
			}
			else
			{
				vpipeSetting.LiquidPipeDiameter = vrefrigerantPipeInfo["LiquidDiameter"];
			}
			if (string.IsNullOrEmpty(vrefrigerantPipeInfo["GasDiameter"]))
			{
				vpipeSetting.GasPipeDiameter = "22.23";
			}
			else
			{
				vpipeSetting.GasPipeDiameter = vrefrigerantPipeInfo["GasDiameter"];
			}
			if (string.IsNullOrEmpty(vrefrigerantPipeInfo["IsLocateAssist"]))
			{
				vpipeSetting.IsLocateAssist = true;
			}
			else
			{
				vpipeSetting.IsLocateAssist = !(vrefrigerantPipeInfo["IsLocateAssist"] == "0");
			}
			if (string.IsNullOrEmpty(vrefrigerantPipeInfo["IsLocateAssist"]))
			{
				vpipeSetting.AssistLength = 100.0;
			}
			else
			{
				vpipeSetting.AssistLength = Convert.ToDouble(vrefrigerantPipeInfo["AssistLength"]);
			}
			if (string.IsNullOrEmpty(vrefrigerantPipeInfo["AssistAngle"]))
			{
				vpipeSetting.AssistAngle = 0.0;
			}
			else
			{
				vpipeSetting.AssistAngle = Convert.ToDouble(vrefrigerantPipeInfo["AssistAngle"]);
			}
			if (string.IsNullOrEmpty(vrefrigerantPipeInfo["IsCustom"]))
			{
				vpipeSetting.IsCustom = true;
			}
			else
			{
				vpipeSetting.IsCustom = !(vrefrigerantPipeInfo["IsCustom"] == "0");
			}
			if (string.IsNullOrEmpty(vrefrigerantPipeInfo["CustomNum"]))
			{
				vpipeSetting.CustomNum = "1";
			}
			else
			{
				vpipeSetting.CustomNum = vrefrigerantPipeInfo["CustomNum"];
			}
			if (string.IsNullOrEmpty(vrefrigerantPipeInfo["IsAreaNum"]))
			{
				vpipeSetting.IsAreaNum = false;
			}
			else
			{
				vpipeSetting.IsAreaNum = !(vrefrigerantPipeInfo["IsAreaNum"] == "0");
			}
			if (string.IsNullOrEmpty(vrefrigerantPipeInfo["AreaNum"]))
			{
				vpipeSetting.AreaNum = "A";
			}
			else
			{
				vpipeSetting.AreaNum = vrefrigerantPipeInfo["AreaNum"];
			}
			if (string.IsNullOrEmpty(vrefrigerantPipeInfo["IsBuildingNum"]))
			{
				vpipeSetting.IsBuildingNum = false;
			}
			else
			{
				vpipeSetting.IsBuildingNum = !(vrefrigerantPipeInfo["IsBuildingNum"] == "0");
			}
			if (string.IsNullOrEmpty(vrefrigerantPipeInfo["IsBuildingNum"]))
			{
				vpipeSetting.BuildingNum = "1";
			}
			else
			{
				vpipeSetting.BuildingNum = vrefrigerantPipeInfo["BuildingNum"];
			}
			if (string.IsNullOrEmpty(vrefrigerantPipeInfo["IsRelative"]))
			{
				vpipeSetting.IsRelative = true;
			}
			else
			{
				vpipeSetting.IsRelative = !(vrefrigerantPipeInfo["IsRelative"] == "0");
			}
			if (string.IsNullOrEmpty(vrefrigerantPipeInfo["StartOffset"]))
			{
				vpipeSetting.StartOffset = "0";
			}
			else
			{
				vpipeSetting.StartOffset = vrefrigerantPipeInfo["StartOffset"];
			}
			if (string.IsNullOrEmpty(vrefrigerantPipeInfo["EndOffset"]))
			{
				vpipeSetting.EndOffset = "2800";
			}
			else
			{
				vpipeSetting.EndOffset = vrefrigerantPipeInfo["EndOffset"];
			}
			vpipeSetting.StartReference = vrefrigerantPipeInfo["StartRefer"];
			vpipeSetting.EndReference = vrefrigerantPipeInfo["EndRefer"];
			return vpipeSetting;
		}

		private bool CheckSettingData(VPipeSetting settings)
		{
			double num;
			if (!settings.IsIntegratedPipe)
			{
				if (settings.IsGasPipe)
				{
					if (!double.TryParse(this.Configs.GasPipeDiameter, out num))
					{
						YJKMessageBox.Show("气管管径值有错误！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
						this.cbbAir.Focus();
						this.cbbAir.SelectAll();
						return false;
					}
				}
				else if (!double.TryParse(this.Configs.LiquidPipeDiameter, out num))
				{
					YJKMessageBox.Show("液管管径值有错误！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
					this.cbbLiquid.Focus();
					this.cbbLiquid.SelectAll();
					return false;
				}
			}
			if (this.Configs.IsLocateAssist)
			{
				if (string.IsNullOrEmpty(this.tbAssistLength.Text.Trim()))
				{
					YJKMessageBox.Show("辅助框长不能为空！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
					this.tbAssistLength.Focus();
					this.tbAssistLength.SelectAll();
					return false;
				}
				if (string.IsNullOrEmpty(this.tbAngle.Text.Trim()))
				{
					YJKMessageBox.Show("辅助框行向角不能为空！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
					this.tbAngle.Focus();
					this.tbAngle.SelectAll();
					return false;
				}
			}
			if (this.Configs.IsCustom && string.IsNullOrEmpty(this.tbCustom.Text.Trim()))
			{
				YJKMessageBox.Show("区号不能为空！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.tbCustom.Focus();
				this.tbCustom.SelectAll();
				return false;
			}
			if (this.Configs.IsAreaNum && string.IsNullOrEmpty(this.tbAreaNum.Text.Trim()))
			{
				YJKMessageBox.Show("区号不能为空！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.tbAreaNum.Focus();
				this.tbAreaNum.SelectAll();
				return false;
			}
			if (this.Configs.IsBuildingNum && string.IsNullOrEmpty(this.tbBuildingNum.Text.Trim()))
			{
				YJKMessageBox.Show("楼号不能为空！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.tbBuildingNum.Focus();
				this.tbBuildingNum.SelectAll();
				return false;
			}
			if (!double.TryParse(this.cbbStartOffset.Text, out num))
			{
				bool isRelative = this.Configs.IsRelative;
				YJKMessageBox.Show(string.Format("{0}必须为有效数字！", Array.Empty<object>()), MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.cbbStartOffset.Focus();
				this.cbbStartOffset.SelectAll();
				return false;
			}
			if (!double.TryParse(this.cbbEndOffset.Text, out num))
			{
				bool isRelative2 = this.Configs.IsRelative;
				YJKMessageBox.Show(string.Format("{0}必须为有效数字！", Array.Empty<object>()), MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.cbbEndOffset.Focus();
				this.cbbEndOffset.SelectAll();
				return false;
			}
			return true;
		}

		private void SetUserData()
		{
			this.userSetting.WriteValue("VRefrigerantPipeInfo", "IsIntegratedPipe", this.Configs.IsIntegratedPipe ? "1" : "0");
			this.userSetting.WriteValue("VRefrigerantPipeInfo", "IsGasPipe", this.Configs.IsGasPipe ? "1" : "0");
			this.userSetting.WriteValue("VRefrigerantPipeInfo", "LiquidDiameter", this.Configs.LiquidPipeDiameter);
			this.userSetting.WriteValue("VRefrigerantPipeInfo", "GasDiameter", this.Configs.GasPipeDiameter);
			this.userSetting.WriteValue("VRefrigerantPipeInfo", "IsLocateAssist", this.Configs.IsLocateAssist ? "1" : "0");
			this.userSetting.WriteValue("VRefrigerantPipeInfo", "AssistLength", this.Configs.AssistLength.ToString());
			this.userSetting.WriteValue("VRefrigerantPipeInfo", "AssistAngle", this.Configs.AssistAngle.ToString());
			this.userSetting.WriteValue("VRefrigerantPipeInfo", "IsCustom", this.Configs.IsCustom ? "1" : "0");
			this.userSetting.WriteValue("VRefrigerantPipeInfo", "CustomNum", this.Configs.CustomNum);
			this.userSetting.WriteValue("VRefrigerantPipeInfo", "IsAreaNum", this.Configs.IsAreaNum ? "1" : "0");
			this.userSetting.WriteValue("VRefrigerantPipeInfo", "AreaNum", this.Configs.AreaNum);
			this.userSetting.WriteValue("VRefrigerantPipeInfo", "IsBuildingNum", this.Configs.IsBuildingNum ? "1" : "0");
			this.userSetting.WriteValue("VRefrigerantPipeInfo", "BuildingNum", this.Configs.BuildingNum);
			this.userSetting.WriteValue("VRefrigerantPipeInfo", "IsRelative", this.Configs.IsRelative ? "1" : "0");
			this.userSetting.WriteValue("VRefrigerantPipeInfo", "StartRefer", this.Configs.StartReference);
			this.userSetting.WriteValue("VRefrigerantPipeInfo", "StartOffset", this.Configs.StartOffset);
			this.userSetting.WriteValue("VRefrigerantPipeInfo", "EndRefer", this.Configs.EndReference);
			this.userSetting.WriteValue("VRefrigerantPipeInfo", "EndOffset", this.Configs.EndOffset);
			this.userSetting.WriteValue("VRefrigerantPipeInfo", "BottomLevel", this.Configs.BottomLevel);
			this.userSetting.WriteValue("VRefrigerantPipeInfo", "TopLevel", this.Configs.TopLevel);
		}

		private IList<string> GetPipeDiameters()
		{
			IList<string> list = new List<string>();
			ICollection<MEPSize> pipeSegmentInfo = this.GetPipeSegmentInfo();
			if (pipeSegmentInfo == null)
			{
				using (List<List<string>>.Enumerator enumerator = new ClassRefrigerantPipeCreateInfo().GetPipeStorage().GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						List<string> list2 = enumerator.Current;
						list.Add(list2[0].ToDouble(0.0).ToString());
					}
					return list;
				}
			}
			foreach (MEPSize mepsize in pipeSegmentInfo)
			{
				list.Add(Math.Round(mepsize.NominalDiameter * 304.8, 2, MidpointRounding.AwayFromZero).ToString());
			}
			return list;
		}

		private ICollection<MEPSize> GetPipeSegmentInfo()
		{
			foreach (Element element in new OperateSegmentFitting(this.doc).GetAllPipeSegment())
			{
				PipeSegment pipeSegment = (PipeSegment)element;
				if (pipeSegment.Name == "铜 - 焊接")
				{
					return pipeSegment.GetSizes();
				}
			}
			return null;
		}

		private IList<string> GetLevels(Autodesk.Revit.DB.Document doc)
		{
			IList<string> list = new List<string>();
			foreach (Element element in new FilteredElementCollector(doc).OfClass(typeof(Level)).ToElements())
			{
				Level level = element as Level;
				list.Add(level.Name);
			}
			return list;
		}

		private IList<string> CreateStartOffset(int interval = 10)
		{
			IList<string> list = new List<string>();
			int num = -350;
			for (int i = 0; i <= interval; i++)
			{
				list.Add(num.ToString());
				num += 50;
			}
			return list;
		}

		private IList<string> CreateEndOffset(int interval = 10)
		{
			IList<string> list = new List<string>();
			int num = 2800;
			for (int i = interval; i >= 0; i--)
			{
				list.Add(num.ToString());
				num -= 50;
			}
			return list;
		}

		private void FormDrawVRefrigerantPipe_MouseLeave(object sender, EventArgs e)
		{
			FormDrawVRefrigerantPipe.SetForegroundWindow(new YJKWindowHandle(Process.GetCurrentProcess().MainWindowHandle).Handle);
		}

		private void FormDrawVRefrigerantPipe_FormClosing(object sender, FormClosingEventArgs e)
		{
			this.SetUserData();
		}

		private void tbAssistLength_KeyPress(object sender, KeyPressEventArgs e)
		{
			if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != '\b' && e.KeyChar != '\r')
			{
				e.Handled = true;
				return;
			}
		}

		private void tbAssistLength_Validating(object sender, CancelEventArgs e)
		{
			double assistLength;
			if (!double.TryParse(this.tbAssistLength.Text.Trim(), out assistLength))
			{
				YJKMessageBox.Show("请输入有效数字！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.tbAssistLength.Focus();
				this.tbAssistLength.Text = this.Configs.AssistLength.ToString();
				this.tbAssistLength.SelectAll();
				return;
			}
			this.Configs.AssistLength = assistLength;
		}

		private void tbAngle_Validating(object sender, CancelEventArgs e)
		{
			double num;
			if (!double.TryParse(this.tbAngle.Text.Trim(), out num))
			{
				YJKMessageBox.Show("请输入有效数字！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.tbAngle.Focus();
				this.tbAngle.Text = this.Configs.AssistAngle.ToString();
				this.tbAngle.SelectAll();
				return;
			}
			if (num < 0.0 || num >= 90.0)
			{
				YJKMessageBox.Show("辅助框行向角的范围为0-90度，且不能等于90度！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.tbAngle.Focus();
				this.tbAngle.Text = this.Configs.AssistAngle.ToString();
				this.tbAngle.SelectAll();
				return;
			}
			this.Configs.AssistAngle = num;
		}

		private void tbCustom_Validating(object sender, CancelEventArgs e)
		{
			System.Windows.Forms.TextBox textBox = (System.Windows.Forms.TextBox)sender;
			if (!Regex.IsMatch(textBox.Text, "^[0-9a-zA-Z'_]+$"))
			{
				YJKMessageBox.Show("文本框值不能为空且必须由英文字母、数字或'_组成！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				textBox.Focus();
				this.tbCustom.Text = this.Configs.CustomNum;
				textBox.SelectAll();
				return;
			}
			this.Configs.CustomNum = this.tbCustom.Text;
		}

		private void cbbOffset_KeyPress(object sender, KeyPressEventArgs e)
		{
			if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != '\b' && e.KeyChar != '\r' && e.KeyChar != '-')
			{
				e.Handled = true;
				return;
			}
		}

		private void cbbOffset_Validating(object sender, CancelEventArgs e)
		{
			string arg = string.Empty;
			System.Windows.Forms.ComboBox comboBox = sender as System.Windows.Forms.ComboBox;
			string name = comboBox.Name;
			if (!(name == "cbbStartOffset"))
			{
				if (name == "cbbEndOffset")
				{
					arg = (this.Configs.IsRelative ? "终点偏移量" : "终点标高");
				}
			}
			else
			{
				arg = (this.rbRelative.Checked ? "起点偏移量" : "起点标高");
			}
			int num;
			if (!int.TryParse(comboBox.Text, out num))
			{
				YJKMessageBox.Show(string.Format("{0}必须为有效数字！", arg), MessageBoxButtons.OK, MessageBoxIcon.Hand);
				comboBox.Focus();
				comboBox.SelectAll();
				return;
			}
		}

		private void cbAreaNum_CheckedChanged(object sender, EventArgs e)
		{
			if ((sender as CheckBox).Name == "cbAreaNum")
			{
				this.tbAreaNum.Enabled = this.cbAreaNum.Checked;
				return;
			}
			this.tbBuildingNum.Enabled = this.cbBuildingNum.Checked;
		}

		public bool CheckUIData()
		{
			double num;
			if (!double.TryParse(this.cbbLiquid.Text, out num))
			{
				YJKMessageBox.Show("液管管径值有错误！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.cbbLiquid.Focus();
				this.cbbLiquid.Text = this.Configs.LiquidPipeDiameter;
				this.cbbLiquid.SelectAll();
				return false;
			}
			if (!double.TryParse(this.cbbAir.Text, out num))
			{
				YJKMessageBox.Show("气管管径值有错误！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.cbbAir.Focus();
				this.cbbAir.Text = this.Configs.GasPipeDiameter;
				this.cbbAir.SelectAll();
				return false;
			}
			if (this.Configs.IsLocateAssist)
			{
				if (string.IsNullOrEmpty(this.tbAssistLength.Text.Trim()))
				{
					YJKMessageBox.Show("辅助框长不能为空！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
					this.tbAssistLength.Focus();
					this.tbAssistLength.Text = this.Configs.AssistLength.ToString();
					this.tbAssistLength.SelectAll();
					return false;
				}
				if (!double.TryParse(this.tbAssistLength.Text.Trim(), out num))
				{
					YJKMessageBox.Show("辅助框长必须为有效数字！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
					this.tbAssistLength.Focus();
					this.tbAssistLength.Text = this.Configs.AssistLength.ToString();
					this.tbAssistLength.SelectAll();
					return false;
				}
				if (string.IsNullOrEmpty(this.tbAngle.Text.Trim()))
				{
					YJKMessageBox.Show("辅助框行向角不能为空!", MessageBoxButtons.OK, MessageBoxIcon.Hand);
					this.tbAngle.Focus();
					this.tbAngle.Text = this.Configs.AssistAngle.ToString();
					this.tbAngle.SelectAll();
					return false;
				}
				if (!double.TryParse(this.tbAngle.Text.Trim(), out num))
				{
					YJKMessageBox.Show("辅助框行向角必须为有效数字！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
					this.tbAngle.Focus();
					this.tbAngle.Text = this.Configs.AssistAngle.ToString();
					this.tbAngle.SelectAll();
					return false;
				}
			}
			if (this.rbCustom.Checked && !Regex.IsMatch(this.tbCustom.Text.Trim(), "^[0-9a-zA-Z'_]+$"))
			{
				YJKMessageBox.Show("自定义编号值不能为空且必须由英文字母、数字或'_组成！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.tbCustom.Focus();
				this.tbCustom.Text = this.Configs.CustomNum;
				this.tbCustom.SelectAll();
				return false;
			}
			if (this.cbAreaNum.Checked && !Regex.IsMatch(this.tbAreaNum.Text.Trim(), "^[0-9a-zA-Z'_]+$"))
			{
				YJKMessageBox.Show("区号不能为空且必须由英文字母、数字或'_组成！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.tbAreaNum.Focus();
				this.tbAreaNum.Text = this.Configs.AreaNum;
				this.tbAreaNum.SelectAll();
				return false;
			}
			if (this.cbBuildingNum.Checked && !Regex.IsMatch(this.tbBuildingNum.Text.Trim(), "^[0-9a-zA-Z'_]+$"))
			{
				YJKMessageBox.Show("楼号不能为空且必须由英文字母、数字或'_组成！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.tbBuildingNum.Focus();
				this.tbBuildingNum.Text = this.Configs.BuildingNum;
				this.tbBuildingNum.SelectAll();
				return false;
			}
			if (string.IsNullOrEmpty(this.cbbStartRefer.Text))
			{
				YJKMessageBox.Show("起点参照不能为空！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.cbbStartRefer.Focus();
				return false;
			}
			if (string.IsNullOrEmpty(this.cbbEndRefer.Text))
			{
				YJKMessageBox.Show("终点参照不能为空！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.cbbEndRefer.Focus();
				return false;
			}
			if (!double.TryParse(this.cbbStartOffset.Text, out num))
			{
				string arg = this.Configs.IsRelative ? "起点偏移量" : "起点标高";
				YJKMessageBox.Show(string.Format("{0}必须为有效数字！", arg), MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.cbbStartOffset.Focus();
				this.cbbStartOffset.Text = (this.Configs.IsRelative ? this.Configs.StartOffset : this.Configs.BottomLevel);
				this.cbbStartOffset.SelectAll();
				return false;
			}
			if (!double.TryParse(this.cbbEndOffset.Text, out num))
			{
				string arg2 = this.Configs.IsRelative ? "终点偏移量" : "终点标高";
				YJKMessageBox.Show(string.Format("{0}必须为有效数字！", arg2), MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.cbbEndOffset.Focus();
				this.cbbEndOffset.Text = (this.Configs.IsRelative ? this.Configs.EndOffset : this.Configs.TopLevel);
				this.cbbEndOffset.SelectAll();
				return false;
			}
			this.Configs.IsIntegratedPipe = this.rbWhole.Checked;
			this.Configs.IsGasPipe = this.rbGas.Checked;
			this.Configs.LiquidPipeDiameter = this.cbbLiquid.Text;
			this.Configs.GasPipeDiameter = this.cbbAir.Text;
			this.Configs.IsLocateAssist = this.cbLocate.Checked;
			this.Configs.IsCustom = this.rbCustom.Checked;
			this.Configs.CustomNum = this.tbCustom.Text.Trim();
			this.Configs.IsAreaNum = this.cbAreaNum.Checked;
			this.Configs.AreaNum = this.tbAreaNum.Text.Trim();
			this.Configs.IsBuildingNum = this.cbBuildingNum.Checked;
			this.Configs.BuildingNum = this.tbBuildingNum.Text.Trim();
			this.Configs.AssistLength = Convert.ToDouble(this.tbAssistLength.Text.Trim());
			this.Configs.AssistAngle = Convert.ToDouble(this.tbAngle.Text.Trim());
			this.Configs.IsRelative = this.rbRelative.Checked;
			this.Configs.StartReference = this.cbbStartRefer.Text;
			this.Configs.EndReference = this.cbbEndRefer.Text;
			if (this.rbRelative.Checked)
			{
				this.Configs.StartOffset = this.cbbStartOffset.Text;
				this.Configs.EndOffset = this.cbbEndOffset.Text;
			}
			else
			{
				this.Configs.BottomLevel = this.cbbStartOffset.Text.Trim();
				this.Configs.TopLevel = this.cbbEndOffset.Text.Trim();
			}
			return true;
		}

		private void SimulationPressESC()
		{
			int bVk = 27;
			int dwFlags = 0;
			int dwFlags2 = 2;
			FormDrawVRefrigerantPipe.keybd_event((byte)bVk, 0, dwFlags, 0);
			FormDrawVRefrigerantPipe.keybd_event((byte)bVk, 0, dwFlags2, 0);
		}

		private void cbLocate_CheckedChanged(object sender, EventArgs e)
		{
			if (this.cbLocate.Checked)
			{
				this.tbAssistLength.Enabled = true;
				this.tbAngle.Enabled = true;
				return;
			}
			this.tbAssistLength.Enabled = false;
			this.tbAngle.Enabled = false;
		}

		private void tbAreaNum_Validating(object sender, CancelEventArgs e)
		{
			if (string.IsNullOrEmpty(this.tbAreaNum.Text.Trim()))
			{
				YJKMessageBox.Show("区号不能为空！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.tbAreaNum.Focus();
				this.tbAreaNum.Text = this.Configs.AreaNum;
				this.tbAreaNum.SelectAll();
			}
		}

		private void tbBuildingNum_Validating(object sender, CancelEventArgs e)
		{
			if (string.IsNullOrEmpty(this.tbBuildingNum.Text.Trim()))
			{
				YJKMessageBox.Show("楼号不能为空！", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.tbBuildingNum.Focus();
				this.tbBuildingNum.Text = this.Configs.BuildingNum;
				this.tbBuildingNum.SelectAll();
				return;
			}
			this.Configs.BuildingNum = this.tbBuildingNum.Text;
		}

		private void cbbStartOffset_Validating(object sender, CancelEventArgs e)
		{
			double num;
			if (!double.TryParse(this.cbbStartOffset.Text, out num))
			{
				string arg = this.Configs.IsRelative ? "偏移量" : "起点标高";
				YJKMessageBox.Show(string.Format("{0}必须为有效数字！", arg), MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.cbbStartOffset.Focus();
				this.cbbStartOffset.Text = (this.Configs.IsRelative ? this.Configs.StartOffset : this.Configs.BottomLevel);
				this.cbbStartOffset.SelectAll();
				return;
			}
			if (this.rbRelative.Checked)
			{
				this.Configs.StartOffset = num.ToString();
				return;
			}
			this.Configs.BottomLevel = num.ToString();
		}

		private void cbbEndOffset_Validating(object sender, CancelEventArgs e)
		{
			double num;
			if (!double.TryParse(this.cbbEndOffset.Text, out num))
			{
				string arg = this.Configs.IsRelative ? "偏移量" : "终点标高";
				YJKMessageBox.Show(string.Format("{0}必须为有效数字！", arg), MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.cbbEndOffset.Focus();
				this.cbbEndOffset.Text = (this.Configs.IsRelative ? this.Configs.EndOffset : this.Configs.TopLevel);
				this.cbbEndOffset.SelectAll();
				return;
			}
			if (this.rbRelative.Checked)
			{
				this.Configs.EndOffset = num.ToString();
				return;
			}
			this.Configs.TopLevel = num.ToString();
		}

		private void FormDrawVRefrigerantPipe_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\u001b')
			{
				base.Close();
			}
		}

		private double[] GetViewRange(Autodesk.Revit.DB.View view)
		{
			if (!(view is ViewPlan))
			{
				return null;
			}
			Document document = view.Document;
			double[] array = new double[2];
			if (view.GenLevel.GetParameter("立面") != null)
			{
				Parameter parameter = view.GenLevel.GetParameter("立面");
				array[0] = parameter.AsDouble();
			}
			IEnumerable<Element> enumerable = new HYSystemElementFilter(document).GetElementsByBICategory(BuiltInCategory.OST_Levels).ToList<Element>();
			SortedSet<double> sortedSet = new SortedSet<double>();
			foreach (Element element in enumerable)
			{
				if (element is Level && element.GetParameter("立面") != null)
				{
					Parameter parameter2 = element.GetParameter("立面");
					sortedSet.Add(parameter2.AsDouble());
				}
			}
			bool flag = false;
			foreach (double num in sortedSet)
			{
				if (flag)
				{
					array[1] = num;
					break;
				}
				if (num == array[0])
				{
					flag = true;
				}
			}
			if (array[1] <= array[0])
			{
				array[1] = array[0] + 9.84251968503937;
			}
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = Math.Ceiling(array[i] * 304.8);
			}
			return array;
		}

		private Document doc;

		private double[] viewRange = new double[2];

		public VPipeSetting Configs;

		private HVACUserSetting userSetting = new HVACUserSetting();
	}
}
